home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / patches / rs232-2 / miditerm.c < prev    next >
C/C++ Source or Header  |  1989-05-12  |  4KB  |  204 lines

  1. /* MIDITERM.C                              copyright 1989 by Kari Alakuijala */
  2.  
  3. #include <stdio.h>
  4. #include <osbind.h>
  5.  
  6. #define CON 2
  7. #define MIDI 3
  8.  
  9. int i, j;                               /* i contains speed,j 6850 ctrl reg. */
  10. long tmpstck;
  11. char *k = 16776196;                     /* $FFFC04 = MIDI ACIA CTRL register */
  12.  
  13.  
  14.  
  15.  
  16. main()
  17. {
  18.     logo();
  19.     handle_RS_port();
  20.     terminal();
  21. }
  22.  
  23.  
  24. logo()
  25. {
  26.     clearscreen();
  27.     printf("                               Miditerm.C\n");
  28.     printf("                               ----------\n");
  29.     printf("\n\nThis is a sample terminal programme for use with MIDI or the 2nd\n");
  30.     printf("RS-232 interface. A compete multitasking BBS programme under MT C-\n");
  31.     printf("shell will come out after 6 months. This file is only added to show\n");
  32.     printf("some programming examples and to test the 2nd RS-232 interface.\n\n");
  33.     printf("Enter some parameters:\n\n");
  34. }
  35.  
  36.  
  37. handle_RS_port()
  38. {
  39.     getspeed();                     /* Get datas from console and */
  40.     setspeed();                     /* set them to timer A of 68901. */
  41.     clearscreen();
  42.     getparms();                     /* Get datas from console and */
  43.     setparms();                     /* set them to MIDI ACIA ctrl reg. */
  44. }
  45.  
  46.  
  47. terminal()
  48. {
  49.     char c, d;
  50.     clearscreen();
  51.     printf("VT52 -terminal mode activated. Press CONTROL-A to enter commands:\n\n");
  52.     menu();
  53.     while(d!='x')
  54.     {
  55.         d=0;
  56.         while(d!=1)
  57.         {
  58.             if(Bconstat(MIDI))
  59.             {
  60.                 c=Bconin(MIDI);
  61.                 Bconout(CON,c);
  62.             }
  63.             if(Bconstat(CON))
  64.             {
  65.                 d=Bconin(CON);
  66.                 if (d!=1) Bconout(MIDI,d);
  67.             }
  68.         }
  69.         Cursconf(3,0);          /* jamms cursor */
  70.         while (Bconstat(CON));
  71.         d=Bconin(CON);    
  72.         Cursconf(2,0);          /* resumes blinking cursor */
  73.         if(d!='b' & d!='l' & d!='h' & d!='x' & d!='v' & d!='p')
  74.         {
  75.             Bconout(MIDI,1);
  76.             Bconout(MIDI,d);
  77.         }
  78.  
  79.         if (d=='b')
  80.         {
  81.             supervise(96,10);
  82.         }
  83.  
  84.         if (d=='l')
  85.         {
  86.             supervise(96,150);
  87.         }
  88.  
  89.         if (d=='h')
  90.         {
  91.             supervise(64,120);
  92.         }
  93.  
  94.         if (d=='x')
  95.         {
  96.             printf("\n\nReturn to Desktop!\n");
  97.             delay(60);
  98.         }
  99.  
  100.         if (d=='v')
  101.         {
  102.             getspeed();
  103.             setspeed();
  104.         }
  105.  
  106.         if (d=='p')
  107.         {
  108.             printf("\n");
  109.             getparms();
  110.             setparms();
  111.         }
  112.     }
  113. }
  114.  
  115.  
  116. getspeed()
  117. {
  118.     while (i<75 || i>19200)
  119.     {
  120.         i=0;
  121.         printf("\nGive me the 2nd RS speed in bps (75, ... ,4800,6400,9600,19200): ");
  122.         scanf("%d",&i);
  123.     }
  124.     i=19200/i;                      /* 75-19200 --> 256-1 */
  125.     i=i&255;                        /* 256 --> 0 */             
  126.     delay(60);
  127. }
  128.  
  129.  
  130. getparms()
  131. {
  132.     printf("Give me the settings for word lenght/stop bits/parity\n\n");
  133.     printf("  1) 7 databits, 2 stopbits, even parity\n");
  134.     printf("  2) 7 databits, 2 stopbits, odd parity\n");
  135.     printf("  3) 7 databits, 1 stopbit,  even parity\n");
  136.     printf("  4) 7 databits, 1 stopbit,  odd parity\n");
  137.     printf("  5) 8 databits, 2 stopbits, no parity\n");
  138.     printf("  6) 8 databits, 1 stopbit,  no parity\n");
  139.     printf("  7) 8 databits, 1 stopbit,  even parity\n");
  140.     printf("  8) 8 databits, 1 stopbit,  odd parity\n");
  141.     while(j<1 || j>8)
  142.     {
  143.         j=0;
  144.         printf("\nGive me (1-8): ");
  145.         scanf("%d",&j);
  146.     }
  147.     j=(j-1)*4+129;
  148.     delay(60);
  149. }
  150.  
  151.  
  152. setspeed()
  153. {
  154.     Xbtimer(0,1,i&255,-1);          /* start timer A of 68901
  155.                 Value of 68901's Timer A ctrl register: 1
  156.                 Value of 68901's Timer A data register: i */
  157. }
  158.  
  159.  
  160. setparms()
  161. {
  162.     tmpstck=Super((long)0);
  163.     *k=j;
  164.     Super(tmpstck);                 /* set integer J to 6850 control
  165.                                        register at $FFFC04 */
  166. }
  167.  
  168.  
  169. clearscreen()
  170. {
  171.     Bconout(CON,27);
  172.     Bconout(CON,'E');
  173. }
  174.  
  175.  
  176. delay(loops)
  177. int loops;
  178. {
  179.     int loop;
  180.     for(loop=1;loop<=loops;loop++)Vsync();
  181. }
  182.  
  183.  
  184. menu()
  185. {
  186.         printf("  b) Send break.\n");
  187.         printf("  l) Send long break.\n");
  188.         printf("  h) Drop DTR (hangup).\n");
  189.         printf("  x) Return to Desktop.\n");
  190.         printf("  v) Set 2nd RS speed.\n");
  191.         printf("  p) Set 2nd RS other parameters.\n\n\n");
  192. }
  193.  
  194.  
  195. supervise(add,dely)
  196. int add,dely;
  197. {
  198. j=j+add;
  199. setparms();
  200. delay(dely);
  201. j=j-add;
  202. setparms();
  203. }
  204.